<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Coupon extends Model
{
    use HasFactory;

    protected $appends = [
        'status_text',
    ];
    protected $fillable = ['number','name','description','type','amount','discount_rate','max_discount','start_date','end_date','valid_days','total_quantity','used_quantity','remarks','status'];

    const POSTONLY = ['number','name','description','type','amount','discount_rate','max_discount','start_date','end_date','valid_days','total_quantity','used_quantity','remarks','status'];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function getStatusTextAttribute()
    {
        $arr = ['active'=>'可领取','inactive'=>'未生效','expired'=>'已过期','disabled'=>'已禁用'];
        return $arr[$this->status];
    }



    public function courses()
    {
        return $this->hasMany(ColumnCourse::class,'column_id','id')->with('course');
    }
}
